package com.hyc.algorithm.StackandQueue;

import java.util.Stack;

/**
 * @projectName: DataStructure
 * @package: com.hyc.algorithm.StackandQueue
 * @className: StackAnalogQueue
 * @author: 冷环渊 doomwatcher
 * @description: TODO
 * @date: 2022/2/27 20:26
 * @version: 1.0
 */
public class StackAnalogQueue {
    public static void main(String[] args) {
        myQueue myQueue = new myQueue(10);
        myQueue.push(1);
        myQueue.push(2);
        myQueue.push(3);
        System.out.println(myQueue.pop());
        System.out.println(myQueue.pop());
        System.out.println(myQueue.pop());
    }

}

class myQueue {
    Stack<Integer> stack1;
    Stack<Integer> stack2;
    int maxsize;
    int size;

    public myQueue(int size) {
        this.maxsize = size;
        stack1 = new Stack();
        stack2 = new Stack();
    }

    public void push(int val) {
        if (maxsize >= size) {
            stack1.push(val);
            size++;
        }
    }

    public int pop() {
        while (!stack1.isEmpty()) {
            stack2.push(stack1.pop());
        }
        int result = stack2.pop();
        while (!stack2.isEmpty()) {
            stack1.push(stack2.pop());
        }
        return result;
    }
}
